export enum StorageType {
    Local = 'Local',
    Session = 'Session'
}

export class StorageHandler {
    // 存储 storage
    setItem (type: StorageType, key: string, value: string) {
        if (type === StorageType.Local) {
            localStorage.setItem(key, value)
        } else {
            sessionStorage.setItem(key, value)
        }
    }

    // 获取
    getItem (type: StorageType, key: string) {
        if (type === StorageType.Local) {
            if (localStorage.getItem(key)) {
               return localStorage.getItem(key)
            }
        } else {
            if (sessionStorage.getItem(key)) {
               return sessionStorage.getItem(key)
            }
        }
    }

    // 移除
    removeItem (type: StorageType, key: string) {
       if (type === StorageType.Local) {
           if (localStorage.getItem(key)) localStorage.removeItem(key)
       } else {
           if (sessionStorage.getItem(key)) sessionStorage.removeItem(key)
       }
    }

    // 清除
    clear (type: StorageType) {
        if (type === StorageType.Local) {
            localStorage.clear()
        } else {
            sessionStorage.clear()
        }
    }
}

// 这里使用localstorage
export const storageType = StorageType.Local